package com.jdkreader.concurrency.queue;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class TestToastQueue {

    public static void main(String[] args) throws Exception {
        final long waitTime = 8 * 1000;
        final long awaitTime = 5 * 1000;

        ToastQueue dryQueue = new ToastQueue(),
                butteredQueue = new ToastQueue(),
                finishedQueue = new ToastQueue();

        ExecutorService exec= Executors.newCachedThreadPool();
        exec.execute(new Toaster(dryQueue));
        exec.execute(new Butterer(dryQueue,butteredQueue));
        exec.execute(new Jammer(butteredQueue,finishedQueue));
        exec.execute(new Eater(finishedQueue));
        //FIXME throw InterruptedException
        TimeUnit.SECONDS.sleep(5);
        exec.shutdownNow();
//        try{
//            exec.shutdown();
//            if(!exec.awaitTermination(awaitTime,TimeUnit.MILLISECONDS)){
//                exec.shutdownNow();
//            }
//        }catch (InterruptedException e){
//            e.printStackTrace();
//            exec.shutdownNow();
//        }
    }
}
